#!/bin/bash
# AI-Powered SSH Terminal - Conda Environment Setup Script for Linux/macOS
# This script sets up the conda environment for the project

echo "========================================"
echo " AI-Powered SSH Terminal Setup"
echo "========================================"

# Check if conda is installed
if ! command -v conda &> /dev/null; then
    echo "❌ ERROR: Conda is not installed or not in PATH"
    echo "Please install Miniconda or Anaconda first"
    echo "Download from: https://docs.conda.io/en/latest/miniconda.html"
    exit 1
fi

echo "✓ Found Conda installation"
conda --version

# Create conda environment from environment.yml
echo ""
echo "📦 Creating conda environment 'ai-terminal'..."
conda env create -f environment.yml

if [ $? -ne 0 ]; then
    echo "❌ ERROR: Failed to create conda environment"
    echo "Try running: conda env remove -n ai-terminal"
    echo "Then run this script again"
    exit 1
fi

echo ""
echo "========================================"
echo " ✅ Setup Complete!"
echo "========================================"
echo ""
echo "To activate the environment:"
echo "   conda activate ai-terminal"
echo ""
echo "To start the server:"
echo "   python start_server.py"
echo ""
echo "To deactivate when done:"
echo "   conda deactivate"
echo ""

# Ask if user wants to activate immediately
read -p "🤔 Activate environment now? (y/n): " activate
if [[ $activate =~ ^[Yy]$ ]]; then
    echo ""
    echo "🚀 Activating environment..."
    echo "Environment will be activated in a new shell"
    echo "Run 'python start_server.py' to start the server"
    exec bash --rcfile <(echo ". ~/.bashrc; conda activate ai-terminal")
else
    echo ""
    echo "💡 Remember to run 'conda activate ai-terminal' before using the application"
fi